package com.atguigu.mapreduce.wordcount;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;

public class WordCountDriver {


    public static void main(String[] args) throws IOException, InterruptedException, ClassNotFoundException {
        // 1. 声明配置对象
        Configuration conf = new Configuration();
        // 2. 获取Job对象
        Job job = Job.getInstance(conf);
        // 3. 给Job对象设置相关信息
        // 指定当前Job中的Mapper和Reducer
        job.setMapperClass(WordCountMapper.class);
        job.setReducerClass(WordCountReducer.class);
        // 指定当前Job的Map阶段输出的key和value的类型
        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(IntWritable.class);
        // 指定当前Job最终输出的key和value的类型
        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(IntWritable.class);

        // 指定当前Job的输入输出路径
        FileInputFormat.addInputPath(job, new Path("E:\\input\\wcinput"));
        FileOutputFormat.setOutputPath(job, new Path("E:\\output\\wcinput_out3"));
        // 提交Job
        job.waitForCompletion(true);
    }
}
